package oj;

import java.util.Arrays;
import java.util.Comparator;

public class Num853 {
    public int carFleet(int target, int[] position, int[] speed) {
        if(position.length==1){
            return 1;
        }
        double[][] arr=new double[position.length][2];
        for (int i = 0; i < position.length; i++) {
            arr[i][0]=position[i];
            arr[i][1]=(double)(target-position[i])/speed[i];
        }
        Arrays.sort(arr,Comparator.comparingDouble(a->a[0]));
        double maxTime=arr[position.length-1][1];
        int ret=0;
        for (int i = position.length-1; i >=1 ; i--) {
            if(arr[i-1][1]>maxTime){
                ret++;
                maxTime=arr[i-1][1];
            }
        }
        ret++;
        return ret;
    }
}
